<template>
    <el-dialog :title="!dataForm.id ? '新建' : '编辑'" :close-on-click-modal="false" :visible.sync="visible"
        class="SHZY-dialog SHZY-dialog_center" lock-scroll width="600px" append-to-body>
        <el-row :gutter="15" class="">
            <el-form ref="elForm" :model="dataForm" size="small" label-width="100px" label-position="right" :rules="rules">
                <el-col :span="24">
                    <el-form-item label="客户编码" prop="customerId">
                        <!-- <el-select v-model='dataForm.customerId' placeholder='请选择' clearable :style="{ width: '100%' }">
                            <el-option v-for="(item, index) in customerList" :key="index" :label="item.name"
                                :value="item.id"></el-option>
                        </el-select> -->
                        <!-- <SHZY-select :list="customerList" placeholder="请选择"
								v-model:bindValue="dataForm.customerId"  label="name" value="code"  isConcat></SHZY-select> -->
                    <el-input v-model='dataForm.customerId' placeholder='请输入' maxlength="50" clearable required show-word-limit
							:style='{ "width": "100%" }'>
						</el-input>
                         </el-form-item> 
                </el-col>
                <el-col :span="24">
                    <el-form-item label="模板信息" prop="fileInfo">
                        <SHZY-UploadFz v-model='dataForm.fileInfo' required :fileSize='5' sizeUnit='MB' :limit='1'
                            buttonText='点击上传'>
                        </SHZY-UploadFz>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="有效标志" prop="enabledMark">
                        <el-switch v-model='dataForm.enabledMark' :active-value='1' :inactive-value='0'>
                        </el-switch>
                    </el-form-item>
                </el-col>
            </el-form>
        </el-row>
        <span slot="footer" class="dialog-footer">
            <el-button @click="visible = false">取 消</el-button>
            <el-button type="primary" @click="dataFormSubmit()" :loading="btnLoading">确 定</el-button>
        </span>
    </el-dialog>
</template>
<script>
import { getPrintTemplateCustomerInfo, createPrintTemplateCustomer, updatePrintTemplateCustomer } from '@/api/common/printTemplateCustomer'
import { getCustomerAll } from '@/api/common/customer'

export default {
    components: {},
    props: [],
    data() {
        return {
            btnLoading: false,
            loading: false,
            visible: false,
            dataForm: {
                id: '',
                templateId: '',
                customerId: '',
                fileInfo: [],
                enabledMark: 1,
                customercode:''
            },
            rules: {
                customerId: [
                    {
                        required: true,
                        message: '请输入客户编码',
                        trigger: '"blur"'
                    },
                ],
                fileInfo: [
                    {
                        required: true,
                        message: '请输入模板信息',
                        trigger: '"click"'
                    },
                ],
            },
            //customerList: []
        }
    },
    computed: {},
    watch: {},
    created() {
        // getCustomerAll().then(res => {
        //     this.customerList = res.data.list
        // })
    },
    mounted() {
    },
    methods: {
        goBack() {
            this.$emit('refresh')
        },
        init(id, templateId) {
            this.dataForm.id = id || 0;
            this.dataForm.templateId = templateId || 0;
            this.visible = true;
            this.$nextTick(() => {
                this.$refs['elForm'].resetFields();
                if (this.dataForm.id) {
                    getPrintTemplateCustomerInfo(this.dataForm.id).then(res => {
                        this.dataForm = res.data;
                        //this.dataForm = res.data.data;
                        //this.dataForm.customerId=res.data.customercode[0];
                        if (!this.dataForm.fileInfo) this.dataForm.fileInfo = [];
                    })
                }
            });
        },
        dataFormSubmit() {
            this.$refs['elForm'].validate((valid) => {
                if (valid) {
                    this.btnLoading = true;
                    const formMethod = !this.dataForm.id ? createPrintTemplateCustomer : updatePrintTemplateCustomer;
                    formMethod(this.dataForm).then((res) => {
                        this.btnLoading = false;
                        this.$message({
                            message: res.msg,
                            type: 'success',
                            duration: 1000,
                            onClose: () => {
                                this.visible = false,
                                    this.$emit('refresh', true)
                            }
                        })
                    }).catch((res) => {
                        this.btnLoading = false;
                    })
                }
            })
        },
    }
}
</script>
